package com.wen.mall.controller;

import com.github.pagehelper.PageInfo;
import com.wen.mall.service.ProductService;
import com.wen.mall.vo.ProductDetailVo;
import com.wen.mall.vo.ResponseVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 20212
 */
@Controller
@ResponseBody
@RequestMapping
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/products")
    @ApiOperation("商品列表")
    public ResponseVo<PageInfo> list(@RequestParam(required = false) Integer categoryId, @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        log.info("ControllerepageSize=>" + pageSize);
        return productService.list(categoryId, pageNum, pageSize);
    }

    @GetMapping("/products/{productId}")
    @ApiOperation("商品详情")
    public ResponseVo<ProductDetailVo> detail(@PathVariable Integer productId) {

        return productService.detail(productId);
    }
}
